{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "liquid-integrity",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[3, 4],\n",
       "       [8, 9]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.arange(15).reshape(3,5)\n",
    "print(a)\n",
    "a[:2, 3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "aboriginal-boston",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]]\n",
      "[[ 6  7  8]\n",
      " [11 12 13]]\n",
      "[[188   7   8]\n",
      " [ 11  12  13]]\n",
      "[[ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(15).reshape(3,5)\n",
    "print(a)\n",
    "b = a[1:, 1:4].copy()\n",
    "print(b)\n",
    "b[0][0] = 188\n",
    "print(b)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "iraqi-grenada",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.36449719  0.36886052  0.36865508  0.34802616 -1.06903343]\n",
      " [-0.99695136  0.59026988 -0.07157375 -0.02439628 -0.67274312]\n",
      " [-0.42037977 -1.05551053 -0.42815789  0.30619494  0.04115599]]\n",
      "[[False  True  True  True False]\n",
      " [False  True False False False]\n",
      " [False False False  True  True]]\n",
      "[[-0.36449719  8.          8.          8.         -1.06903343]\n",
      " [-0.99695136  8.         -0.07157375 -0.02439628 -0.67274312]\n",
      " [-0.42037977 -1.05551053 -0.42815789  8.          8.        ]]\n"
     ]
    }
   ],
   "source": [
    "# 布尔索引\n",
    "a = np.random.randn(15).reshape((3,5))\n",
    "print(a)\n",
    "print(a>0)\n",
    "# 把所有大于零的数字改成8\n",
    "a[a > 0] =8\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "casual-transcription",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.60429185  1.76519288  0.1684     -0.41789931]\n",
      " [ 0.91817916 -0.53960044 -0.58796853 -2.95398883]\n",
      " [ 0.3342724  -0.46843289 -0.16256765  1.96391019]\n",
      " [-0.44059709  0.04669039  0.587547   -0.90085326]\n",
      " [ 0.15315217  0.19083218  0.31331225 -0.92025762]\n",
      " [-0.06330004 -0.60503442 -1.32194213 -0.95376855]]\n",
      "[[ 0.60429185  1.76519288  0.1684     -0.41789931]\n",
      " [ 0.91817916 -0.53960044 -0.58796853 -2.95398883]\n",
      " [ 0.15315217  0.19083218  0.31331225 -0.92025762]]\n"
     ]
    }
   ],
   "source": [
    "# 6个名字\n",
    "names = np.array(['zs', 'ls', 'ww', 'zl', 'zs', 'ms'])\n",
    "# 这6个名字对应的6次考试结果，共四门课\n",
    "scores = np.random.randn(6,4)\n",
    "print(scores)\n",
    "# 选出ms的成绩\n",
    "print(scores[(names == 'zs') | (names == 'ls')])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "rolled-actor",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]\n",
      " [12 13 14 15]\n",
      " [16 17 18 19]\n",
      " [20 21 22 23]\n",
      " [24 25 26 27]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[20, 21, 22, 23],\n",
       "       [12, 13, 14, 15],\n",
       "       [24, 25, 26, 27],\n",
       "       [ 4,  5,  6,  7]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(28).reshape(7,4)\n",
    "print(a)\n",
    "a[[5, 3, 6, 1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "surprising-bunch",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
